import { isPlainObject } from "./helpers";

function bindActionCreator(action, dispatch) {
    return function (...args) {
        return dispatch(action, ...args);
    }
}


export default function bindActionCreators(actions, dispatch) {
    if (isPlainObject(actions)) {
        const retObj = {};
        for (let prop in actions) {
            // 函数，要拿到这个函数的返回值
            const actionFn =  actions[prop];
            retObj[prop] = bindActionCreator(actionFn(), dispatch);
        }
        return retObj;
    } else {
        return {}
    }

} 